package com.um.jdy.mp.order.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.mp.order.entity.dto.FreeUserDTO;
import com.um.jdy.mp.order.entity.vo.FreeUserItemVO;
import com.um.jdy.mp.order.manager.FreeUserManager;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ListParams;
import com.um.springboot.starter.orm.params.PageParams;
import com.um.springboot.starter.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 免费用户
 *
 * @author cs
 * 日期 2023/6/26
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "免费用户")
@Validated
@RestController
@RequestMapping("/api/v1/cms/free/user")
@SaCheckLogin
public class FreeUserController extends BaseController<FreeUserManager> {

    /**
     * 列表
     *
     * @param name
     * @return
     */
    @ApiOperation("列表")
    @GetMapping("list")
    public Response<List<FreeUserItemVO>> list(@ApiParam(value = "昵称") String name) {
        ListParams params = new ListParams();
        if (!StringUtil.isEmpty(name)) {
            params.getCondition().put("m.nickname", StringUtil.getQueryParam(name));
        }
        return manager.list(params);
    }

    /**
     * 分页列表
     *
     * @param page_no
     * @param page_size
     * @param name
     * @return
     */
    @ApiOperation("分页列表")
    @GetMapping("page")
    public Response<Page<FreeUserItemVO>> page(@ApiParam(value = "页码") @NotNull Integer page_no,
                                               @ApiParam(value = "数据量") @NotNull Integer page_size,
                                               @ApiParam(value = "昵称") String name) {
        PageParams params = new PageParams();
        params.setPageNo(page_no);
        params.setPageSize(page_size);
        if (!StringUtil.isEmpty(name)) {
            params.getCondition().put("m.nickname", StringUtil.getQueryParam(name));
        }
        return manager.page(params);
    }

    /**
     * 分页列表/精准手机号查询用户
     *
     * @param mobile
     * @return
     */
    @ApiOperation("用户列表或精准手机号查询用户")
    @GetMapping("/get")
    public Response getUserByMobile(@ApiParam(value = "手机号") String mobile) {
        return manager.getUserByMobile(mobile);
    }

    @ApiOperation("详情")
    @GetMapping({"{id}"})
    public Response get(@PathVariable String id) {
        return manager.get(id);
    }

    /**
     * 增加
     *
     * @param dto
     * @return
     */
    @ApiOperation("增加")
    @PostMapping("")
    public Response add(@RequestBody FreeUserDTO dto) {
        return manager.add(dto);
    }

    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
//    @ApiOperation("批量删除")
//    @DeleteMapping
//    public Response deleteIds(@ApiParam(value = "删除的id", required = true) @RequestBody List<String> ids) {
//        return manager.deleteIds(ids);
//    }
}
